package com.ruoyi.train.controller;


import com.ruoyi.train.domain.ExamApplication;
import com.ruoyi.train.domain.Vo.ExamApplicationVo;
import com.ruoyi.train.service.IExamApplicationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.HttpStatus;

import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 考试点录入成绩Controller
 * 
 * @author wusihao
 * @date 2023-04-13
 */
@RestController
@RequestMapping("/exam/importGrade")
public class examImportGradeController extends BaseController
{
    @Autowired
    private IExamApplicationService examApplicationService;

    /**
     * 查询提交考试申请列表
     */
    @ApiOperation("查询考试申请表列表")
    @GetMapping("/list")
    public TableDataInfo list(ExamApplicationVo examApplicationVo)
    {
        startPage();
        List<ExamApplicationVo> list = examApplicationService.selectExamApplicationVoImportList(examApplicationVo);
        return getDataTable(list);
    }

    /**
     * 导出提交考试申请列表
     */
    @ApiOperation("导出考试申请表")
    @Log(title = "提交考试申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamApplication examApplication)
    {
        List<ExamApplication> list = examApplicationService.selectExamApplicationList(examApplication);
        ExcelUtil<ExamApplication> util = new ExcelUtil<ExamApplication>(ExamApplication.class);
        util.exportExcel(response, list, "提交考试申请数据");
    }

    /**
     * 获取提交考试申请详细信息
     */
    @ApiOperation("查看考试申请表详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        ExamApplicationVo data = examApplicationService.selectExamApplicationVoById(id);
        return success(data);
    }

    /**
     * 新增提交考试申请
     */
    @ApiOperation("新增考试申请表")
    @Log(title = "提交考试申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamApplication examApplication)
    {
        return toAjax(examApplicationService.insertExamApplication(examApplication));
    }

    /**
     * 删除提交考试申请
     */
    @ApiOperation("删除考试申请表")
    @Log(title = "提交考试申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examApplicationService.deleteExamApplicationByIds(ids));
    }

    /**
     * 将信息加入到考试合格申请
     */
    @ApiOperation("将信息加入到考试合格申请")
    @Log(title = "提交考试申请", businessType = BusinessType.UPDATE)
    @GetMapping("/examCertificate/{applicationId}")
    public AjaxResult remove(@PathVariable Long applicationId)
    {
        return toAjax(examApplicationService.addToExamCertificateApplication(applicationId));
    }

    /**
     * 修改考试点录入成绩
     */
    @PutMapping
    public AjaxResult examPlacegetGrade(@RequestBody ExamApplication examApplication)
    {
        return toAjax(examApplicationService.updateExamPlacegetGrade(examApplication));
    }

    @PostMapping("/uploadPdf")
    public ResponseEntity<String> uploadPdf(@RequestBody MultipartFile file) throws IOException {
        // 处理上传的pdf文件，实现方式根据实际需求而定
        // 在此处可以将pdf文件保存到服务器中，数据库中或者进行其他操作
        byte[] pdfBytes = file.getBytes();
        // ... 对pdf文件进行处理 ...
        return new ResponseEntity<>("Upload Success", HttpStatus.OK); // 返回上传成功提示消息以及响应状态码
    }

}
